#ifndef _BSP
#define _BSP

#include <vector>
#include "Scaler.h"
#include "dataTypes.h"
using namespace std;

class BSP_Node{
public:
	sRectangle _rect;
	BSP_Node* _parent;
	BSP_Node* _left;
	BSP_Node* _right;

	BSP_Node();
	BSP_Node(sRectangle aRect);
	BSP_Node(sRectangle aRect, BSP_Node* aParent);
	
	bool separate();
	inline bool isLeaf(){if(_left == NULL || _right == NULL) return true; else return false;}
	inline bool hasLeafs(){if(_left->isLeaf() || _right->isLeaf()) return true; else return false;}
};

class BSP{
public:
	BSP();
	~BSP();

	vector<sRectangle> produce(int aX1, int aY1, int aX2, int aY2, int aLevels);
	vector<sRectangle> produce(sRectangle aRect, int aLevels);

private:
	BSP_Node* _root;
	vector<BSP_Node*> _leafs;
	void findLeafs(BSP_Node* aNode);
	void destroyTree(BSP_Node* aNode);
};

#endif